﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using agvcsimulator.Module;
using agvcontroller.Log;


namespace agvcsimulator.GUI
{
    /// <summary>
    /// Interaction logic for UCTerminalSim.xaml
    /// </summary>
    public partial class UCTerminalSim : UserControl
    {
        CTerminalSim TerminalSim;
        Logger Log;

        public UCTerminalSim(CTerminalSim terminalSim)
        {
            InitializeComponent();

            TerminalSim = terminalSim;

            RegisterEvent();

            InitParameter();

            InitUI();
        }

        void InitParameter()
        {
            Log = new Logger(string.Format("UCTerminalSim[{0}]", TerminalSim.Name)); ;

            Log.Info("InitParameter");
        }

        void InitUI()
        {
        }

        void RegisterEvent()
        {
            Logger.onDisplayLog += new deleLogDisplay(Logger_onDisplayLog);
        }

        void Logger_onDisplayLog(object sender, string msg, enumLogLevel level)
        {
            if (((Logger)sender).LogName == TerminalSim.SimDriver.Name || ((Logger)sender).LogName == TerminalSim.Name)
            {
                DisplayLog(msg);
            }
        }

        void DisplayLog(string msg)
        {
            System.Windows.Threading.DispatcherOperation
          dispatcherOp = tbLog.Dispatcher.BeginInvoke(
          System.Windows.Threading.DispatcherPriority.Normal,
          new Action(
            delegate()
            {
                tbLog.AppendText(string.Format("{0}\r\n", msg));
                tbLog.ScrollToEnd();
            }
            ));
        }


        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton11_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton12_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton13_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton14_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton15_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton16_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton17_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton18_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton19_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void uCLEDButton20_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            TerminalSim.Connect();
        }

        private void btnDisconnect_Click(object sender, RoutedEventArgs e)
        {
            TerminalSim.Disconnect();
        }

        private void uCLEDButton1_MouseUp(object sender, MouseButtonEventArgs e)
        {
            TerminalSim.RequestJob(1);
        }

        private void uCLEDButton2_MouseUp(object sender, MouseButtonEventArgs e)
        {
            TerminalSim.RequestJob(2);
        }

        private void uCLEDButton3_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton4_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton5_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton6_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton7_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton8_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton9_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton10_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uCLEDButton11_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }
    }
}
